#include <iostream>
#include <deque>

using namespace std;

int a[30][10], degree[30], dp[30], trace[30];
bool next[30][30];
deque<int> q;

int k, n, pos, ccount;

void input()
{
	for (int i = 0; i < k; i++)
		for (int j = 0; j < n; j++) cin >> a[i][j];
}

void swap(int *a, int *b)
{
	int temp = *a;
	*a = *b;
	*b = temp;
}

void init()
{
	for (int i = 0; i < k; i++)
	{
		for (int j = 0; j < n; j++)
			for (int r = j+1; r < n; r++)
				if (a[i][j] > a[i][r]) swap(&a[i][j], &a[i][r]);
	}

	for (int i = 0; i < k; i++)
		for (int j = 0; j < k; j++)
			if (i != j)
			{
				next[i][j] = true;
				for (int r = 0; r < n; r++)
					if (a[i][r] <= a[j][r])
					{
						next[i][j] = false;
						break;
					}
			}

	for (int i = 0; i < k; i++)
	{
		degree[i] = 0;
		for (int j = 0; j < k; j++)
			if (i != j && next[j][i]) degree[i]++;
	}
}

void process()
{
	q.clear();
	ccount = 0;

	for (int u = 0; u < k; u++) trace[u] = -1;

	while (true)
	{
		for (int u = 0; u < k; u++)
			if (degree[u] == 0) q.push_back(u);

		if (q.empty()) break;

		ccount++;
		while (!q.empty())
		{
			int u = q.front();
			q.pop_front();
			degree[u] = -1;

			pos = u;

			for (int v = 0; v < k; v++)
				if (next[u][v])
				{
					degree[v]--;
					if (degree[v] == 0) trace[v] = u;
				}
		}
	}
}

void findTrace(int v)
{
	if (trace[v] == -1)
	{
		cout << v+1 << endl;
		return;
	}
	else
	{
		cout << v+1 << " ";
		findTrace(trace[v]);
	}
}
void output()
{
	cout << ccount << endl;
	findTrace(pos);
}

int main()
{
	while (cin >> k >> n)
	{
		input();
		init();
		process();
		output();
	}
	return 0;
}
